﻿package com.calefk.util {
    import flash.display.MovieClip;

    public class TransitionFade {
        
        private var mBackground:int;
        private var mFuctionEndInTime:Function;
        private var mFuctionEndOutTime:Function;
        private var mOutTime:int;
        private var mFade:Fade;
        
        public function TransitionFade(canvas:MovieClip , 
                background:int , inTime:int ,
                outTime:int, 
                functionEndInTime:Function ,
                functionEndOutTime:Function ,
                width:int = 600 , height:int = 400){
            
            mBackground = background;
            mFuctionEndInTime = functionEndInTime;
            mFuctionEndOutTime = functionEndOutTime;
            mOutTime = outTime;
            
            mFade = new Fade(canvas , mBackground , width , height);
            mFade.startFade(Fade.FADE_IN , endInFade , inTime);
        }
        
        private function endInFade():void {
            mFade.startFade(Fade.FADE_OUT , endOutFade , mOutTime);
            // call end in function
            mFuctionEndInTime();
        }
        
        private function endOutFade():void {
            mFade.clean();
            mFade = null;
            // call end in function
            mFuctionEndOutTime();
        }
        
        public function clean():void {
            if (mFade) {
                mFade.clean();
                mFade = null;
            }
            mFuctionEndInTime = null;
            mFuctionEndOutTime = null;
        }
    }
}